//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.Blackboard.Wcf
{
    using System;
    using Microsoft.Research.eResearch.Blackboard.Common;
    using Microsoft.Research.eResearch.Blackboard.Interfaces;
    using Microsoft.Research.eResearch.Blackboard.Wcf.WcfNotificationMessageService;

    /// <summary>
    /// Provides a WCF implementation of the <see cref="INotificationMessageSender"/> interface.
    /// This implementation allows the Blackboard to notify subscribers of new blackboard messages.
    /// </summary>
    public class WcfNotificationMessageClient : INotificationMessageSender
    {
        /// <summary>
        /// Notifies the subscriber at the specified address of a new BlackboardMessage.
        /// </summary>
        /// <param name="address">The subscriber's address.</param>
        /// <param name="message">The outgoing BlackboardMessage.</param>
        public void Notify(Uri address, BlackboardMessage message)
        {
            WcfNotificationMessageServiceClient client =
                new WcfNotificationMessageServiceClient(
                    "WcfNotificationMessageClient",
                    address.ToString());
            client.Open();
            client.Notify(message);
            client.Close();
        }
    }
}
